package org.flexlancer.databases
{
	import org.flexlancer.utils.DateTimeUtils;
	
	public class Expenses
	{
		public static const TABLE:String = "expenses";
//this.CreateTable("expenses",["expid INTEGER PRIMARY KEY AUTOINCREMENT","expdate TEXT","exptitle TEXT","expcat TEXT","expamount INTEGER"]);

		public static function Add(exptitle:String,expcat:String,expamount:Number,expdate:String = ""):void{
			try{
				var insertObj:Object = new Object();
				expdate = expdate != "" ? expdate : DateTimeUtils.TodayCutOffDateString;  
				insertObj.exptitle = exptitle;
				insertObj.expcat = expcat;
				insertObj.expamount = expamount;
				insertObj.expdate = expdate;
				
				DatabaseManager.Manager.Insert(TABLE,insertObj);
			}catch(err:Error){
				throw err;
			}
		}

		public static function List(condition:String = ""):Array{
			try{
				return DatabaseManager.Manager.Select(TABLE,null,condition,"expcat");
			}catch(err:Error){
				throw err;
			}
			return new Array;
		}

		public static function Delete(condition:String = ""):void{
			try{
				DatabaseManager.Manager.Delete(TABLE,condition);
			}catch(err:Error){
				throw err;
			}
		}
	}
}